package com.liangtian.mdm.dm.sql.controller;


import com.liangtian.mdm.base.controller.BaseController;
import com.liangtian.mdm.base.utils.ResultObject;
import com.liangtian.mdm.dm.sql.service.GenTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/genTable")
public class GenTableController extends BaseController {

    @Autowired
    private GenTableService genTableService;

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject create(@RequestParam("model_id") String id) {

        ResultObject result = null;
        try {
            boolean ret = genTableService.createTable(id);
            int f = ret ? 1 : 0;
            result = new ResultObject(f, "创建成功", "创建失败");
        } catch (Exception e) {
            result = new ResultObject(0, "创建成功", e.getMessage());
        }
        return result;
    }

    @RequestMapping(value = "/drop", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject drop(@RequestParam("model_id") String id) {

        ResultObject result = null;
        try {
            boolean ret = genTableService.dropTable(id);
            int f = ret ? 1 : 0;
            result = new ResultObject(f, "删除成功", "删除失败");
        } catch (Exception e) {
            result = new ResultObject(0, "创建成功", e.getMessage());
        }
        return result;
    }

}
